package lanou.autohome.find.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.find.beans.FindFenLeiBean;

/**
 * Created by dllo on 16/8/24.
 */
public class FindFenLeiAdapter extends RecyclerView.Adapter<FindFenLeiAdapter.FenViewHolder>{

    private Context mcontext;
    private FindFenLeiBean findFenLeiBean;

    public FindFenLeiAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setFindFenLeiBean(FindFenLeiBean findFenLeiBean) {
        this.findFenLeiBean = findFenLeiBean;
        notifyDataSetChanged();
    }

    @Override
    public FenViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_find_fenlei , null);
        FenViewHolder fenViewHolder = new FenViewHolder(view);
        return fenViewHolder;
    }

    @Override
    public void onBindViewHolder(FenViewHolder holder, int position) {

        holder.title.setText(findFenLeiBean.getResult().getFunctionlist().get(position).getTitle());

        NetTool netTool = new NetTool();
        netTool.getImage(findFenLeiBean.getResult().getFunctionlist().get(position).getIconurl() , holder.iconurl);
    }

    @Override
    public int getItemCount() {
        return findFenLeiBean != null ? findFenLeiBean.getResult().getFunctionlist().size() : 0;
    }

    public class FenViewHolder extends RecyclerView.ViewHolder {

        TextView title;
        ImageView iconurl;
        public FenViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title_fenlei_find_item);
            iconurl = (ImageView) itemView.findViewById(R.id.iconurl_fenlei_find_item);
        }
    }
}
